package com.hmall.common.config;

import com.hmall.common.interceptors.UserInfoInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration //这个配置要在所有微服务中生效，要被自动扫描到（spring boot自动装配），得加入META-INF\spring.factories文件中
//网关中也引入了common包，但是网关是基于WebFlux响应式编程，不是springMVC,引入该配置会报错，不能引入，因此加入条件
@ConditionalOnClass(DispatcherServlet.class)//springMVC中独有的类 DispatcherServlet.class
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInfoInterceptor());//默认拦截所有路径
    }
}
